<?php


abstract class BaseReceipt extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $status_id;


	
	protected $user_id;


	
	protected $anonymous_id;


	
	protected $uid;


	
	protected $items_qnt;


	
	protected $receipt_items_qnt;


	
	protected $tax;


	
	protected $total_price;


	
	protected $currency_code;


	
	protected $shipping_id;


	
	protected $shipping_price;


	
	protected $updated_at;


	
	protected $created_at;


	
	protected $completed_at;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getAnonymousId()
	{

		return $this->anonymous_id;
	}

	
	public function getUid()
	{

		return $this->uid;
	}

	
	public function getItemsQnt()
	{

		return $this->items_qnt;
	}

	
	public function getReceiptItemsQnt()
	{

		return $this->receipt_items_qnt;
	}

	
	public function getTax()
	{

		return $this->tax;
	}

	
	public function getTotalPrice()
	{

		return $this->total_price;
	}

	
	public function getCurrencyCode()
	{

		return $this->currency_code;
	}

	
	public function getShippingId()
	{

		return $this->shipping_id;
	}

	
	public function getShippingPrice()
	{

		return $this->shipping_price;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCompletedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->completed_at === null || $this->completed_at === '') {
			return null;
		} elseif (!is_int($this->completed_at)) {
						$ts = strtotime($this->completed_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [completed_at] as date/time value: " . var_export($this->completed_at, true));
			}
		} else {
			$ts = $this->completed_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ReceiptPeer::ID;
		}

	} 
	
	public function setStatusId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v) {
			$this->status_id = $v;
			$this->modifiedColumns[] = ReceiptPeer::STATUS_ID;
		}

	} 
	
	public function setUserId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = ReceiptPeer::USER_ID;
		}

	} 
	
	public function setAnonymousId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->anonymous_id !== $v) {
			$this->anonymous_id = $v;
			$this->modifiedColumns[] = ReceiptPeer::ANONYMOUS_ID;
		}

	} 
	
	public function setUid($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->uid !== $v) {
			$this->uid = $v;
			$this->modifiedColumns[] = ReceiptPeer::UID;
		}

	} 
	
	public function setItemsQnt($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->items_qnt !== $v) {
			$this->items_qnt = $v;
			$this->modifiedColumns[] = ReceiptPeer::ITEMS_QNT;
		}

	} 
	
	public function setReceiptItemsQnt($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->receipt_items_qnt !== $v) {
			$this->receipt_items_qnt = $v;
			$this->modifiedColumns[] = ReceiptPeer::RECEIPT_ITEMS_QNT;
		}

	} 
	
	public function setTax($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->tax !== $v) {
			$this->tax = $v;
			$this->modifiedColumns[] = ReceiptPeer::TAX;
		}

	} 
	
	public function setTotalPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->total_price !== $v) {
			$this->total_price = $v;
			$this->modifiedColumns[] = ReceiptPeer::TOTAL_PRICE;
		}

	} 
	
	public function setCurrencyCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->currency_code !== $v) {
			$this->currency_code = $v;
			$this->modifiedColumns[] = ReceiptPeer::CURRENCY_CODE;
		}

	} 
	
	public function setShippingId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->shipping_id !== $v) {
			$this->shipping_id = $v;
			$this->modifiedColumns[] = ReceiptPeer::SHIPPING_ID;
		}

	} 
	
	public function setShippingPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->shipping_price !== $v) {
			$this->shipping_price = $v;
			$this->modifiedColumns[] = ReceiptPeer::SHIPPING_PRICE;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = ReceiptPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = ReceiptPeer::CREATED_AT;
		}

	} 
	
	public function setCompletedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [completed_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->completed_at !== $ts) {
			$this->completed_at = $ts;
			$this->modifiedColumns[] = ReceiptPeer::COMPLETED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->status_id = $rs->getInt($startcol + 1);

			$this->user_id = $rs->getInt($startcol + 2);

			$this->anonymous_id = $rs->getInt($startcol + 3);

			$this->uid = $rs->getString($startcol + 4);

			$this->items_qnt = $rs->getInt($startcol + 5);

			$this->receipt_items_qnt = $rs->getInt($startcol + 6);

			$this->tax = $rs->getInt($startcol + 7);

			$this->total_price = $rs->getInt($startcol + 8);

			$this->currency_code = $rs->getString($startcol + 9);

			$this->shipping_id = $rs->getInt($startcol + 10);

			$this->shipping_price = $rs->getInt($startcol + 11);

			$this->updated_at = $rs->getTimestamp($startcol + 12, null);

			$this->created_at = $rs->getTimestamp($startcol + 13, null);

			$this->completed_at = $rs->getTimestamp($startcol + 14, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 15; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Receipt object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReceiptPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			ReceiptPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(ReceiptPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(ReceiptPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReceiptPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ReceiptPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ReceiptPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = ReceiptPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReceiptPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getStatusId();
				break;
			case 2:
				return $this->getUserId();
				break;
			case 3:
				return $this->getAnonymousId();
				break;
			case 4:
				return $this->getUid();
				break;
			case 5:
				return $this->getItemsQnt();
				break;
			case 6:
				return $this->getReceiptItemsQnt();
				break;
			case 7:
				return $this->getTax();
				break;
			case 8:
				return $this->getTotalPrice();
				break;
			case 9:
				return $this->getCurrencyCode();
				break;
			case 10:
				return $this->getShippingId();
				break;
			case 11:
				return $this->getShippingPrice();
				break;
			case 12:
				return $this->getUpdatedAt();
				break;
			case 13:
				return $this->getCreatedAt();
				break;
			case 14:
				return $this->getCompletedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ReceiptPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getStatusId(),
			$keys[2] => $this->getUserId(),
			$keys[3] => $this->getAnonymousId(),
			$keys[4] => $this->getUid(),
			$keys[5] => $this->getItemsQnt(),
			$keys[6] => $this->getReceiptItemsQnt(),
			$keys[7] => $this->getTax(),
			$keys[8] => $this->getTotalPrice(),
			$keys[9] => $this->getCurrencyCode(),
			$keys[10] => $this->getShippingId(),
			$keys[11] => $this->getShippingPrice(),
			$keys[12] => $this->getUpdatedAt(),
			$keys[13] => $this->getCreatedAt(),
			$keys[14] => $this->getCompletedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReceiptPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setStatusId($value);
				break;
			case 2:
				$this->setUserId($value);
				break;
			case 3:
				$this->setAnonymousId($value);
				break;
			case 4:
				$this->setUid($value);
				break;
			case 5:
				$this->setItemsQnt($value);
				break;
			case 6:
				$this->setReceiptItemsQnt($value);
				break;
			case 7:
				$this->setTax($value);
				break;
			case 8:
				$this->setTotalPrice($value);
				break;
			case 9:
				$this->setCurrencyCode($value);
				break;
			case 10:
				$this->setShippingId($value);
				break;
			case 11:
				$this->setShippingPrice($value);
				break;
			case 12:
				$this->setUpdatedAt($value);
				break;
			case 13:
				$this->setCreatedAt($value);
				break;
			case 14:
				$this->setCompletedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ReceiptPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setStatusId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setUserId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setAnonymousId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setUid($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setItemsQnt($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setReceiptItemsQnt($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setTax($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTotalPrice($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCurrencyCode($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setShippingId($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setShippingPrice($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setUpdatedAt($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setCompletedAt($arr[$keys[14]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ReceiptPeer::DATABASE_NAME);

		if ($this->isColumnModified(ReceiptPeer::ID)) $criteria->add(ReceiptPeer::ID, $this->id);
		if ($this->isColumnModified(ReceiptPeer::STATUS_ID)) $criteria->add(ReceiptPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(ReceiptPeer::USER_ID)) $criteria->add(ReceiptPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(ReceiptPeer::ANONYMOUS_ID)) $criteria->add(ReceiptPeer::ANONYMOUS_ID, $this->anonymous_id);
		if ($this->isColumnModified(ReceiptPeer::UID)) $criteria->add(ReceiptPeer::UID, $this->uid);
		if ($this->isColumnModified(ReceiptPeer::ITEMS_QNT)) $criteria->add(ReceiptPeer::ITEMS_QNT, $this->items_qnt);
		if ($this->isColumnModified(ReceiptPeer::RECEIPT_ITEMS_QNT)) $criteria->add(ReceiptPeer::RECEIPT_ITEMS_QNT, $this->receipt_items_qnt);
		if ($this->isColumnModified(ReceiptPeer::TAX)) $criteria->add(ReceiptPeer::TAX, $this->tax);
		if ($this->isColumnModified(ReceiptPeer::TOTAL_PRICE)) $criteria->add(ReceiptPeer::TOTAL_PRICE, $this->total_price);
		if ($this->isColumnModified(ReceiptPeer::CURRENCY_CODE)) $criteria->add(ReceiptPeer::CURRENCY_CODE, $this->currency_code);
		if ($this->isColumnModified(ReceiptPeer::SHIPPING_ID)) $criteria->add(ReceiptPeer::SHIPPING_ID, $this->shipping_id);
		if ($this->isColumnModified(ReceiptPeer::SHIPPING_PRICE)) $criteria->add(ReceiptPeer::SHIPPING_PRICE, $this->shipping_price);
		if ($this->isColumnModified(ReceiptPeer::UPDATED_AT)) $criteria->add(ReceiptPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(ReceiptPeer::CREATED_AT)) $criteria->add(ReceiptPeer::CREATED_AT, $this->created_at);
		if ($this->isColumnModified(ReceiptPeer::COMPLETED_AT)) $criteria->add(ReceiptPeer::COMPLETED_AT, $this->completed_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ReceiptPeer::DATABASE_NAME);

		$criteria->add(ReceiptPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setStatusId($this->status_id);

		$copyObj->setUserId($this->user_id);

		$copyObj->setAnonymousId($this->anonymous_id);

		$copyObj->setUid($this->uid);

		$copyObj->setItemsQnt($this->items_qnt);

		$copyObj->setReceiptItemsQnt($this->receipt_items_qnt);

		$copyObj->setTax($this->tax);

		$copyObj->setTotalPrice($this->total_price);

		$copyObj->setCurrencyCode($this->currency_code);

		$copyObj->setShippingId($this->shipping_id);

		$copyObj->setShippingPrice($this->shipping_price);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);

		$copyObj->setCompletedAt($this->completed_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ReceiptPeer();
		}
		return self::$peer;
	}

} 